/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kedacom.demo.jmx;

import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;

/**
 *
 * @author Administrator
 */
public class HelloWorld extends NotificationBroadcasterSupport implements HelloWorldMBean {

    private String greeting = null;

    public HelloWorld() {

        this.greeting = "Hello World! I am a Standard MBean ";

    }

    public HelloWorld(String greeting) {

        this.greeting = greeting;

    }

    @Override
    public void setGreeting(String greeting) {
        this.greeting = greeting;
        
        /*
            java.lang.String type

            点分格式的 String 来标识通知，用于通知的简要描述

            java.lang.Object source

            产生通知的 MBean ， 可以是 MBean 对象的引用或是它的ObjectName  

            long sequenceNumber

            在一个通知序列中表示本通知

            long timestamp

            创建通知 的时间戳

            java.lang.String message

            通知源的消息
         */
        Notification notification = new Notification(
                "HelloWorld.setGreeting", this, -1,
                System.currentTimeMillis(), greeting);

        sendNotification(notification);
    }

    @Override
    public String getGreeting() {
        return greeting;
    }

    @Override
    public void printGreeting() {
        System.out.println(greeting);
    }
}
